****TABLE 9****

cd "$main_dir/output/tables/main"

******************************************************************************************************************************************************************
******************************************************************************************************************************************************************
*COLUMN 1 - GLOBAL SAMPLE (HARMONIZED DATASET)********************************************************************************************************************
******************************************************************************************************************************************************************
******************************************************************************************************************************************************************

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs yob_ln_gdppc)

local varlist growth_shock disaster acceleration
foreach var of local varlist {
	merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/`var'_mpd_var_exp.dta", nogen keepusing(w`var'_1)
}

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.

//--------------------------------------------------------
//Create Table 9 (Column 1)
//--------------------------------------------------------

qui reghdfe trust_govt wgrowth_shock_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt wgrowth_shock_1 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_shock_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_9_panel_a.doc, replace dec(3) nocons addtext(Geographic Unit FE, Country, ///
																 Survey, Harmonized) keep(zwgrowth_shock_1) nor2
														
qui reghdfe trust_govt wdisaster_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt wdisaster_1 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zwdisaster_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_9_panel_b.doc, replace dec(3) nocons addtext(Geographic Unit FE, Country, ///
																 Survey, Harmonized) keep(zwdisaster_1)	nor2
														
qui reghdfe trust_govt wacceleration_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt wacceleration_1 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zwacceleration_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_9_panel_c.doc, replace dec(3) nocons addtext(Geographic Unit FE, Country, ///
																 Survey, Harmonized) keep(zwacceleration_1)	nor2
														
														
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
*COLUMN 2 - US SAMPLE (ANES)**********************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

egen scode_survey_year = group(state_code survey_year)

//--------------------------------------------------------
//Create Table 9 (Column 2)
//--------------------------------------------------------															
														
qui reghdfe trust_fed_govt wgrowth_shock_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
local list trust_fed_govt wgrowth_shock_1 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_fed_govt zwgrowth_shock_1 zyob_ln_gdppc if e(sample)==1, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_9_panel_a.doc, append dec(3) nocons addtext(Geographic Unit FE, State, ///
																Survey, ANES) keep(zwgrowth_shock_1) nor2
														
qui reghdfe trust_fed_govt wdisaster_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
local list trust_fed_govt wdisaster_1 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_fed_govt zwdisaster_1 zyob_ln_gdppc if e(sample)==1, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_9_panel_b.doc, append dec(3) nocons addtext(Geographic Unit FE, State, ///
																Survey, ANES) keep(zwdisaster_1) nor2
														
qui reghdfe trust_fed_govt wacceleration_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
local list trust_fed_govt wacceleration_1 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_fed_govt zwacceleration_1 zyob_ln_gdppc if e(sample)==1, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_9_panel_c.doc, append dec(3) nocons addtext(Geographic Unit FE, State, ///
																Survey, ANES) keep(zwacceleration_1) nor2
														

****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
*COLUMN 3 - SWISS SAMPLE (SHP)**********************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************

global basic 	marital edu
global econ	    employment_status occupation income imputed_income
global design 	survey_year age language
global polit    ideology party_member

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/shp_final_panel.dta"

xtset idpers survey_year

gen dummy = 1 if trust_fed_govt_med!=.
bys idpers: egen total_obs = total(dummy)

cap drop sample
gen sample = 1 if live_switz==1 & total_obs>4 & total_obs!=. & age>=15 & age!=.											
														
//--------------------------------------------------------
//Create Table 9 (Column 3)
//--------------------------------------------------------	

summ wdisaster_1 if sample==1, de
scalar disaster = r(p99)

cap drop wwinsz_disaster_1
gen wwinsz_disaster_1 = wdisaster_1
replace wwinsz_disaster_1 = `=disaster' if wdisaster_1>`=disaster' & `=disaster'!=.
drop wdisaster_1
rename wwinsz_disaster_1 wdisaster_1

qui reghdfe trust_fed_govt_med wgrowth_shock_1 if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
local list trust_fed_govt_med wgrowth_shock_1 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_fed_govt_med zwgrowth_shock_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
outreg2 using table_9_panel_a.doc, append dec(3) nocons addtext(Geographic Unit FE, Canton, ///
																Survey, SHP) keep(zwgrowth_shock_1) nor2
														
qui reghdfe trust_fed_govt_med wdisaster_1 if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
local list trust_fed_govt_med wdisaster_1
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_fed_govt_med zwdisaster_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
outreg2 using table_9_panel_b.doc, append dec(3) nocons addtext(Geographic Unit FE, Canton, ///
																Survey, SHP) keep(zwdisaster_1) nor2
														
qui reghdfe trust_fed_govt_med wacceleration_1 if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
local list trust_fed_govt_med wacceleration_1
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_fed_govt_med zwacceleration_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
outreg2 using table_9_panel_c.doc, append dec(3) nocons addtext(Geographic Unit FE, Canton, ///
																Survey, SHP) keep(zwacceleration_1)	nor2												
													
